/*     */ package com.zimbra.cs.mailbox;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.BEncoding;
/*     */ import com.zimbra.common.util.BEncoding.BEncodingException;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class MetadataList
/*     */ {
/*     */   List<Object> list;
/*     */   
/*     */   public MetadataList()
/*     */   {
/*  35 */     this.list = new ArrayList();
/*     */   }
/*     */   
/*     */   public MetadataList(List<?> list) {
/*  39 */     this.list = new ArrayList(list);
/*     */   }
/*     */   
/*     */   public MetadataList(String encoded) throws ServiceException {
/*     */     try {
/*  44 */       this.list = ((List)BEncoding.decode(encoded));
/*     */     } catch (BEncoding.BEncodingException e) {
/*  46 */       throw ServiceException.FAILURE("error decoding list metadata: " + encoded, e);
/*     */     }
/*     */   }
/*     */   
/*     */   public int size() {
/*  51 */     return this.list.size();
/*     */   }
/*     */   
/*     */   public boolean isEmpty() {
/*  55 */     return this.list.isEmpty();
/*     */   }
/*     */   
/*     */   public int getVersion() {
/*  59 */     return 10;
/*     */   }
/*     */   
/*     */   public MetadataList copy(MetadataList source) {
/*  63 */     this.list.addAll(source.list);
/*  64 */     return this;
/*     */   }
/*     */   
/*     */   public <T> List<T> asList()
/*     */   {
/*  69 */     List<T> result = new ArrayList();
/*  70 */     for (Object obj : this.list) {
/*  71 */       if (obj != null)
/*     */       {
/*  73 */         if ((obj instanceof Map)) {
/*  74 */           result.add(new Metadata((Map)obj));
/*  75 */         } else if ((obj instanceof List)) {
/*  76 */           result.add(new MetadataList((List)obj));
/*     */         } else
/*  78 */           result.add(obj);
/*     */       }
/*     */     }
/*  81 */     return result;
/*     */   }
/*     */   
/*     */   public MetadataList add(Object value) {
/*  85 */     if (value != null) {
/*  86 */       this.list.add(value);
/*     */     }
/*  88 */     return this;
/*     */   }
/*     */   
/*     */   public MetadataList add(int value) {
/*  92 */     this.list.add(Integer.valueOf(value));
/*  93 */     return this;
/*     */   }
/*     */   
/*     */   public MetadataList add(long value) {
/*  97 */     this.list.add(Long.valueOf(value));
/*  98 */     return this;
/*     */   }
/*     */   
/*     */   public MetadataList add(double value) {
/* 102 */     this.list.add(new Double(value));
/* 103 */     return this;
/*     */   }
/*     */   
/*     */   public MetadataList add(boolean value) {
/* 107 */     this.list.add(new Boolean(value));
/* 108 */     return this;
/*     */   }
/*     */   
/*     */   public MetadataList add(Metadata value) {
/* 112 */     if (value != null) {
/* 113 */       this.list.add(value.map);
/*     */     }
/* 115 */     return this;
/*     */   }
/*     */   
/*     */   public MetadataList add(MetadataList value) {
/* 119 */     if (value != null) {
/* 120 */       this.list.add(value.list);
/*     */     }
/* 122 */     return this;
/*     */   }
/*     */   
/*     */   public void remove(int index) {
/* 126 */     if (index < this.list.size())
/* 127 */       this.list.remove(index);
/*     */   }
/*     */   
/*     */   public void remove(Object value) {
/* 131 */     this.list.remove(value);
/*     */   }
/*     */   
/*     */   public String get(int index) throws ServiceException {
/* 135 */     Object obj = this.list.get(index);
/* 136 */     return checkNull(index, obj).toString();
/*     */   }
/*     */   
/*     */   public int getInt(int index) throws ServiceException {
/* 140 */     return parseInt(index, get(index));
/*     */   }
/*     */   
/*     */   public long getLong(int index) throws ServiceException {
/* 144 */     return parseLong(index, get(index));
/*     */   }
/*     */   
/*     */   public double getDouble(int index) throws ServiceException {
/* 148 */     return parseDouble(index, get(index));
/*     */   }
/*     */   
/*     */   public boolean getBool(int index) throws ServiceException {
/* 152 */     return parseBool(index, get(index));
/*     */   }
/*     */   
/*     */   public MetadataList getList(int index) throws ServiceException {
/* 156 */     Object value = this.list.get(index);
/* 157 */     if ((value instanceof List)) {
/* 158 */       return new MetadataList((List)value);
/*     */     }
/* 160 */     throw ServiceException.INVALID_REQUEST("invalid/null value for index: " + index, null);
/*     */   }
/*     */   
/*     */   public Metadata getMap(int index) throws ServiceException {
/* 164 */     Object value = this.list.get(index);
/* 165 */     if ((value instanceof Map))
/*     */     {
/* 167 */       Map<String, ?> cast = (Map)value;
/* 168 */       return new Metadata(cast);
/*     */     }
/* 170 */     throw ServiceException.INVALID_REQUEST("invalid/null value for attribute: " + index, null);
/*     */   }
/*     */   
/*     */   private static Object checkNull(int index, Object value) throws ServiceException {
/* 174 */     if (value == null)
/* 175 */       throw ServiceException.INVALID_REQUEST("null element in list: " + index, null);
/* 176 */     return value;
/*     */   }
/*     */   
/*     */   public static int parseInt(int index, String value) throws ServiceException
/*     */   {
/*     */     try {
/* 182 */       return Integer.parseInt(value);
/*     */     } catch (NumberFormatException e) {
/* 184 */       throw ServiceException.INVALID_REQUEST("invalid value for index: " + index, e);
/*     */     }
/*     */   }
/*     */   
/*     */   public static long parseLong(int index, String value) throws ServiceException
/*     */   {
/*     */     try {
/* 191 */       return Long.parseLong(value);
/*     */     } catch (NumberFormatException e) {
/* 193 */       throw ServiceException.INVALID_REQUEST("invalid value for index: " + index, e);
/*     */     }
/*     */   }
/*     */   
/*     */   public static double parseDouble(int index, String value) throws ServiceException {
/*     */     try {
/* 199 */       return Double.parseDouble(value);
/*     */     } catch (NumberFormatException e) {
/* 201 */       throw ServiceException.INVALID_REQUEST("invalid value for index: " + index, e);
/*     */     }
/*     */   }
/*     */   
/*     */   public static boolean parseBool(int index, String value) throws ServiceException {
/* 206 */     if ((value.equals("1")) || (value.equalsIgnoreCase("true")))
/* 207 */       return true;
/* 208 */     if ((value.equals("0")) || (value.equalsIgnoreCase("false"))) {
/* 209 */       return false;
/*     */     }
/* 211 */     throw ServiceException.INVALID_REQUEST("invalid boolean value for index: " + index, null);
/*     */   }
/*     */   
/*     */   public String toString()
/*     */   {
/* 216 */     return BEncoding.encode(this.list);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailbox/MetadataList.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */